//
//  SIXClassViewController.m
//  FastDoctor_6
//
//  Created by cool on 16/3/3.
//  Copyright © 2016年 cool. All rights reserved.
//

#import "SIXClassViewController.h"
#import "SIXClassModel.h"
#import "SIXClassViewCell.h"


@interface SIXClassViewController ()<UICollectionViewDataSource,UICollectionViewDelegate>

@property (nonatomic, strong) NSArray *dataArray    ;

@property (nonatomic, strong) UICollectionViewFlowLayout *flowLayout;

@end

static NSString *identifier = @"collectionCell";

@implementation SIXClassViewController

- (NSArray *)dataArray{
    if (nil == _dataArray) {
        
        NSString *path = [[NSBundle mainBundle] pathForResource:@"Class.plist" ofType:nil];
        
        NSArray *tempArray = [NSArray arrayWithContentsOfFile:path];
        
        NSMutableArray *mute = [NSMutableArray array];
        
        for (NSDictionary *dict in tempArray) {
            SIXClassModel *classModel = [SIXClassModel ClassModelWithDict:dict];
            [mute addObject:classModel];
        }
        
        _dataArray = mute;
    }
    return _dataArray;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    _flowLayout = [[UICollectionViewFlowLayout alloc] init];
    
    _flowLayout.itemSize = CGSizeMake(60,60);
    
    _flowLayout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
    
    _flowLayout.minimumInteritemSpacing = 0;
    
    UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0,328, 144) collectionViewLayout:_flowLayout];
    
    [collectionView registerClass:[SIXClassViewCell class] forCellWithReuseIdentifier:identifier];
    
    collectionView.dataSource = self;

    [self.view addSubview:collectionView];
    
    collectionView.backgroundColor = [UIColor cyanColor];

}

//
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return 1;
    
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return self.dataArray.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    SIXClassViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
    SIXClassModel *classModel = self.dataArray[indexPath.row];
    
    cell.classModel = classModel;
    
    return cell;
    
}


- (void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    
    
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
